const path = require('path');

class HomeCtl{
    index(ctx){
        ctx.body="进入首页"
    }
    upload(ctx){
        const file = ctx.request.files.file;//获取文件
        if(!file){ctx.throw(2000,'请传入file参数')}
        const basename = path.basename(file.path);//获取相对路劲
        //ctx.origin   代替了http://localhost:3000
        ctx.body = { url: `${ctx.origin}/uploads/${basename}` };
    }
}

module.exports=new HomeCtl();